﻿using System;
using System.Collections.Generic;
using System.Text;
using QuanLyHocSinh.HeThongXuLy;
using System.Windows.Forms;
using System.Data;

namespace QuanLyHocSinh.HeThongLuuTru
{
    class HocSinhDAO
    {
        public static bool ThemHocSinh(HocSinhDTO hs)
        {
            try
            {
                string sql = "insert into HOCSINH(HoTen, GioiTinh, NgaySinh, DiaChi, Email) values ('" +
                   hs.HoTen + "','" +
                   hs.GioiTinh + "','" +
                   hs.NgaySinh + "','" +
                   hs.DiaChi + "','" +
                   hs.Email + "')";
                DataAccess.ExecNonQuery(sql);
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public static bool SuaHocSinh(HocSinhDTO hs)
        {
            try
            {
                string sql = " Update HOCSINH set HoTen = '" +
                    hs.HoTen + "',GioiTinh = '" +
                    hs.GioiTinh + "',NgaySinh = '" +
                    hs.NgaySinh + "',DiaChi='" +
                    hs.DiaChi + "',Email='" +
                    hs.Email + "' where MaHocSinh=" + hs.MaHocSinh;
                DataAccess.ExecNonQuery(sql);
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public static bool XoaHocSinh(HocSinhDTO hs)
        {
            try
            {
                string sql = "Delete from HOCSINH where MaHocSinh=" + hs.MaHocSinh;
                DataAccess.ExecNonQuery(sql);
                return true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return false;
            }
        }

        public static DataTable DanhSachHocSinh()
        {
            string sql = "select * from HOCSINH";
            return DataAccess.ExecQuery(sql);
        }

    }
}
